package com.sky.controller.user;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @Author Yjr
 * @Date 2025/5/27 9:50
 */
@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "订单管理")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    @ApiOperation("添加订单")
    public Result addOrder(@RequestBody OrdersSubmitDTO dto){

        OrderSubmitVO submitVO= ordersService.addOrder(dto);

        return Result.success(submitVO);
    }


    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = ordersService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    @GetMapping("/historyOrders")
    @ApiOperation("查询历史订单")
    public Result historyOrders(OrdersPageQueryDTO dto) throws Exception {

        return Result.success(ordersService.historyOrders(dto)) ;

    }

    @GetMapping("/orderDetail/{id}")
    @ApiOperation("查询订单详情")
    public Result findOrdersById(@PathVariable Long id) throws Exception {

        OrderVO ordersVo = ordersService.findOrdersById(id);
        return Result.success(ordersVo);
    }

    @PutMapping("cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancelOrders(@PathVariable Long id) throws Exception {
        OrdersCancelDTO dto =new OrdersCancelDTO();
        dto.setId(id);
        ordersService.cancelOrders(dto);
        return Result.success();
    }

    @PostMapping("repetition/{id}")
    @ApiOperation("再来一单")
    public Result repetitionOrders(@PathVariable Long id) throws Exception {

        ordersService.repetitionOrders(id);
        return Result.success();
    }

    @GetMapping("/reminder/{id}")
    @ApiOperation("客户催单")
    public Result reminder(@PathVariable Long id) throws Exception {

        ordersService.reminder(id);
        return Result.success();
    }

}
